using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWALAGEN
    {
        public DataRow Convert2WALAGEN(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWALAGEN(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WALMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WALKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WALWERK"] = " ".PadRight(3 ); 
         dwReturn["WALABT"] = " ".PadRight(3 ); 
         dwReturn["WALWAKZ"] = " ".PadRight(1 ); 
         dwReturn["WALART"] = " ".PadRight(20 ); 
         dwReturn["WALLAGE"] = " ".PadRight(0 ); 
         dwReturn["WALBEZ"] = " ".PadRight(50 ); 
         dwReturn["WALNAME"] = " ".PadRight(2 ); 
         dwReturn["WALWINKEL"] = " ".PadRight(0 ); 
         dwReturn["WALADICKE"] = " ".PadRight(0 ); 
         dwReturn["WALATOLP"] = " ".PadRight(0 ); 
         dwReturn["WALATOLM"] = " ".PadRight(0 ); 
         dwReturn["WALEDICKE"] = " ".PadRight(0 ); 
         dwReturn["WALETOLP"] = " ".PadRight(0 ); 
         dwReturn["WALETOLM"] = " ".PadRight(0 ); 
         dwReturn["WALGEW"] = " ".PadRight(0 ); 
         dwReturn["WALGEWTOLP"] = " ".PadRight(0 ); 
         dwReturn["WALGEWTOLM"] = " ".PadRight(0 ); 
         dwReturn["WALGEWMAEH"] = " ".PadRight(3 ); 
         dwReturn["WALMAEHGRP"] = " ".PadRight(1 ); 
         dwReturn["WALMAEHFKT"] = " ".PadRight(12 ); 
         dwReturn["WALGEWMEEH"] = " ".PadRight(3 ); 
         dwReturn["WALMEEHGRP"] = " ".PadRight(1 ); 
         dwReturn["WALMEEHFKT"] = " ".PadRight(12 ); 
         dwReturn["WALWERT1"] = " ".PadRight(0 ); 
         dwReturn["WALW1TOLP"] = " ".PadRight(0 ); 
         dwReturn["WALW1TOLM"] = " ".PadRight(0 ); 
         dwReturn["WALW1MAEH"] = " ".PadRight(3 ); 
         dwReturn["WALW1MAEHGRP"] = " ".PadRight(1 ); 
         dwReturn["WALW1MAEHFKT"] = " ".PadRight(12 ); 
         dwReturn["WALW1MEEH"] = " ".PadRight(3 ); 
         dwReturn["WALW1MEEHGRP"] = " ".PadRight(1 ); 
         dwReturn["WALW1MEEHFKT"] = " ".PadRight(12 ); 
         dwReturn["WALWERT2"] = " ".PadRight(0 ); 
         dwReturn["WALW2TOLP"] = " ".PadRight(0 ); 
         dwReturn["WALW2TOLM"] = " ".PadRight(0 ); 
         dwReturn["WALW2MAEH"] = " ".PadRight(3 ); 
         dwReturn["WALW2MAEHGRP"] = " ".PadRight(1 ); 
         dwReturn["WALW2MAEHFKT"] = " ".PadRight(12 ); 
         dwReturn["WALW2MEEH"] = " ".PadRight(3 ); 
         dwReturn["WALW2MEEHGRP"] = " ".PadRight(1 ); 
         dwReturn["WALW2MEEHFKT"] = " ".PadRight(12 ); 
         dwReturn["WALWERT3"] = " ".PadRight(0 ); 
         dwReturn["WALW3TOLP"] = " ".PadRight(0 ); 
         dwReturn["WALW3TOLM"] = " ".PadRight(0 ); 
         dwReturn["WALW3MAEH"] = " ".PadRight(3 ); 
         dwReturn["WALW3MAEHGRP"] = " ".PadRight(1 ); 
         dwReturn["WALW3MAEHFKT"] = " ".PadRight(12 ); 
         dwReturn["WALW3MEEH"] = " ".PadRight(3 ); 
         dwReturn["WALW3MEEHGRP"] = " ".PadRight(1 ); 
         dwReturn["WALW3MEEHFKT"] = " ".PadRight(12 ); 
         dwReturn["WALFILLER"] = " ".PadRight(93 ); 
         dwReturn["WALAENZL"] = " ".PadRight(0 ); 
         dwReturn["WALAENB"] = " ".PadRight(8 ); 
         dwReturn["WALAEND"] = " ".PadRight(0 ); 
         dwReturn["WALNEUB"] = " ".PadRight(8 ); 
         dwReturn["WALNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWALAGEN(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWALAGEN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWALAGEN(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWALAGEN(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWALAGEN(dwLocal, ITXDBVERSION);
            }
            UpdateWALAGEN(dwLocal);
        }
        public void InsertWALAGEN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WALAGEN(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWALAGEN(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WALAGEN WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WALAGEN  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WALAGEN";
            Return = Result;
            return Return;
        }
        public void DeleteWALAGEN(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WALAGEN   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWALAGEN(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WALAGEN SET "
                    +"WALMANDANT= :WALMANDANT,"
                    +"WALKUNDNR= :WALKUNDNR,"
                    +"WALWERK= :WALWERK,"
                    +"WALABT= :WALABT,"
                    +"WALWAKZ= :WALWAKZ,"
                    +"WALART= :WALART,"
                    +"WALLAGE= :WALLAGE,"
                    +"WALBEZ= :WALBEZ,"
                    +"WALNAME= :WALNAME,"
                    +"WALWINKEL= :WALWINKEL,"
                    +"WALADICKE= :WALADICKE,"
                    +"WALATOLP= :WALATOLP,"
                    +"WALATOLM= :WALATOLM,"
                    +"WALEDICKE= :WALEDICKE,"
                    +"WALETOLP= :WALETOLP,"
                    +"WALETOLM= :WALETOLM,"
                    +"WALGEW= :WALGEW,"
                    +"WALGEWTOLP= :WALGEWTOLP,"
                    +"WALGEWTOLM= :WALGEWTOLM,"
                    +"WALGEWMAEH= :WALGEWMAEH,"
                    +"WALMAEHGRP= :WALMAEHGRP,"
                    +"WALMAEHFKT= :WALMAEHFKT,"
                    +"WALGEWMEEH= :WALGEWMEEH,"
                    +"WALMEEHGRP= :WALMEEHGRP,"
                    +"WALMEEHFKT= :WALMEEHFKT,"
                    +"WALWERT1= :WALWERT1,"
                    +"WALW1TOLP= :WALW1TOLP,"
                    +"WALW1TOLM= :WALW1TOLM,"
                    +"WALW1MAEH= :WALW1MAEH,"
                    +"WALW1MAEHGRP= :WALW1MAEHGRP,"
                    +"WALW1MAEHFKT= :WALW1MAEHFKT,"
                    +"WALW1MEEH= :WALW1MEEH,"
                    +"WALW1MEEHGRP= :WALW1MEEHGRP,"
                    +"WALW1MEEHFKT= :WALW1MEEHFKT,"
                    +"WALWERT2= :WALWERT2,"
                    +"WALW2TOLP= :WALW2TOLP,"
                    +"WALW2TOLM= :WALW2TOLM,"
                    +"WALW2MAEH= :WALW2MAEH,"
                    +"WALW2MAEHGRP= :WALW2MAEHGRP,"
                    +"WALW2MAEHFKT= :WALW2MAEHFKT,"
                    +"WALW2MEEH= :WALW2MEEH,"
                    +"WALW2MEEHGRP= :WALW2MEEHGRP,"
                    +"WALW2MEEHFKT= :WALW2MEEHFKT,"
                    +"WALWERT3= :WALWERT3,"
                    +"WALW3TOLP= :WALW3TOLP,"
                    +"WALW3TOLM= :WALW3TOLM,"
                    +"WALW3MAEH= :WALW3MAEH,"
                    +"WALW3MAEHGRP= :WALW3MAEHGRP,"
                    +"WALW3MAEHFKT= :WALW3MAEHFKT,"
                    +"WALW3MEEH= :WALW3MEEH,"
                    +"WALW3MEEHGRP= :WALW3MEEHGRP,"
                    +"WALW3MEEHFKT= :WALW3MEEHFKT,"
                    +"WALFILLER= :WALFILLER,"
                    +"WALAENZL= :WALAENZL,"
                    +"WALAENB= :WALAENB,"
                    +"WALAEND= :WALAEND,"
                    +"WALNEUB= :WALNEUB,"
                    +"WALNEUD= :WALNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WALMANDANT", OracleType.NVarChar).Value = dwData["WALMANDANT"].ToString(); 
          or1.Parameters.Add("WALKUNDNR", OracleType.NVarChar).Value = dwData["WALKUNDNR"].ToString(); 
          or1.Parameters.Add("WALWERK", OracleType.NVarChar).Value = dwData["WALWERK"].ToString(); 
          or1.Parameters.Add("WALABT", OracleType.NVarChar).Value = dwData["WALABT"].ToString(); 
          or1.Parameters.Add("WALWAKZ", OracleType.NVarChar).Value = dwData["WALWAKZ"].ToString(); 
          or1.Parameters.Add("WALART", OracleType.NVarChar).Value = dwData["WALART"].ToString(); 
          or1.Parameters.Add("WALLAGE", OracleType.NVarChar).Value = dwData["WALLAGE"].ToString(); 
          or1.Parameters.Add("WALBEZ", OracleType.NVarChar).Value = dwData["WALBEZ"].ToString(); 
          or1.Parameters.Add("WALNAME", OracleType.NVarChar).Value = dwData["WALNAME"].ToString(); 
          or1.Parameters.Add("WALWINKEL", OracleType.NVarChar).Value = dwData["WALWINKEL"].ToString(); 
          or1.Parameters.Add("WALADICKE", OracleType.NVarChar).Value = dwData["WALADICKE"].ToString(); 
          or1.Parameters.Add("WALATOLP", OracleType.NVarChar).Value = dwData["WALATOLP"].ToString(); 
          or1.Parameters.Add("WALATOLM", OracleType.NVarChar).Value = dwData["WALATOLM"].ToString(); 
          or1.Parameters.Add("WALEDICKE", OracleType.NVarChar).Value = dwData["WALEDICKE"].ToString(); 
          or1.Parameters.Add("WALETOLP", OracleType.NVarChar).Value = dwData["WALETOLP"].ToString(); 
          or1.Parameters.Add("WALETOLM", OracleType.NVarChar).Value = dwData["WALETOLM"].ToString(); 
          or1.Parameters.Add("WALGEW", OracleType.NVarChar).Value = dwData["WALGEW"].ToString(); 
          or1.Parameters.Add("WALGEWTOLP", OracleType.NVarChar).Value = dwData["WALGEWTOLP"].ToString(); 
          or1.Parameters.Add("WALGEWTOLM", OracleType.NVarChar).Value = dwData["WALGEWTOLM"].ToString(); 
          or1.Parameters.Add("WALGEWMAEH", OracleType.NVarChar).Value = dwData["WALGEWMAEH"].ToString(); 
          or1.Parameters.Add("WALMAEHGRP", OracleType.NVarChar).Value = dwData["WALMAEHGRP"].ToString(); 
          or1.Parameters.Add("WALMAEHFKT", OracleType.NVarChar).Value = dwData["WALMAEHFKT"].ToString(); 
          or1.Parameters.Add("WALGEWMEEH", OracleType.NVarChar).Value = dwData["WALGEWMEEH"].ToString(); 
          or1.Parameters.Add("WALMEEHGRP", OracleType.NVarChar).Value = dwData["WALMEEHGRP"].ToString(); 
          or1.Parameters.Add("WALMEEHFKT", OracleType.NVarChar).Value = dwData["WALMEEHFKT"].ToString(); 
          or1.Parameters.Add("WALWERT1", OracleType.NVarChar).Value = dwData["WALWERT1"].ToString(); 
          or1.Parameters.Add("WALW1TOLP", OracleType.NVarChar).Value = dwData["WALW1TOLP"].ToString(); 
          or1.Parameters.Add("WALW1TOLM", OracleType.NVarChar).Value = dwData["WALW1TOLM"].ToString(); 
          or1.Parameters.Add("WALW1MAEH", OracleType.NVarChar).Value = dwData["WALW1MAEH"].ToString(); 
          or1.Parameters.Add("WALW1MAEHGRP", OracleType.NVarChar).Value = dwData["WALW1MAEHGRP"].ToString(); 
          or1.Parameters.Add("WALW1MAEHFKT", OracleType.NVarChar).Value = dwData["WALW1MAEHFKT"].ToString(); 
          or1.Parameters.Add("WALW1MEEH", OracleType.NVarChar).Value = dwData["WALW1MEEH"].ToString(); 
          or1.Parameters.Add("WALW1MEEHGRP", OracleType.NVarChar).Value = dwData["WALW1MEEHGRP"].ToString(); 
          or1.Parameters.Add("WALW1MEEHFKT", OracleType.NVarChar).Value = dwData["WALW1MEEHFKT"].ToString(); 
          or1.Parameters.Add("WALWERT2", OracleType.NVarChar).Value = dwData["WALWERT2"].ToString(); 
          or1.Parameters.Add("WALW2TOLP", OracleType.NVarChar).Value = dwData["WALW2TOLP"].ToString(); 
          or1.Parameters.Add("WALW2TOLM", OracleType.NVarChar).Value = dwData["WALW2TOLM"].ToString(); 
          or1.Parameters.Add("WALW2MAEH", OracleType.NVarChar).Value = dwData["WALW2MAEH"].ToString(); 
          or1.Parameters.Add("WALW2MAEHGRP", OracleType.NVarChar).Value = dwData["WALW2MAEHGRP"].ToString(); 
          or1.Parameters.Add("WALW2MAEHFKT", OracleType.NVarChar).Value = dwData["WALW2MAEHFKT"].ToString(); 
          or1.Parameters.Add("WALW2MEEH", OracleType.NVarChar).Value = dwData["WALW2MEEH"].ToString(); 
          or1.Parameters.Add("WALW2MEEHGRP", OracleType.NVarChar).Value = dwData["WALW2MEEHGRP"].ToString(); 
          or1.Parameters.Add("WALW2MEEHFKT", OracleType.NVarChar).Value = dwData["WALW2MEEHFKT"].ToString(); 
          or1.Parameters.Add("WALWERT3", OracleType.NVarChar).Value = dwData["WALWERT3"].ToString(); 
          or1.Parameters.Add("WALW3TOLP", OracleType.NVarChar).Value = dwData["WALW3TOLP"].ToString(); 
          or1.Parameters.Add("WALW3TOLM", OracleType.NVarChar).Value = dwData["WALW3TOLM"].ToString(); 
          or1.Parameters.Add("WALW3MAEH", OracleType.NVarChar).Value = dwData["WALW3MAEH"].ToString(); 
          or1.Parameters.Add("WALW3MAEHGRP", OracleType.NVarChar).Value = dwData["WALW3MAEHGRP"].ToString(); 
          or1.Parameters.Add("WALW3MAEHFKT", OracleType.NVarChar).Value = dwData["WALW3MAEHFKT"].ToString(); 
          or1.Parameters.Add("WALW3MEEH", OracleType.NVarChar).Value = dwData["WALW3MEEH"].ToString(); 
          or1.Parameters.Add("WALW3MEEHGRP", OracleType.NVarChar).Value = dwData["WALW3MEEHGRP"].ToString(); 
          or1.Parameters.Add("WALW3MEEHFKT", OracleType.NVarChar).Value = dwData["WALW3MEEHFKT"].ToString(); 
          or1.Parameters.Add("WALFILLER", OracleType.NVarChar).Value = dwData["WALFILLER"].ToString(); 
          or1.Parameters.Add("WALAENZL", OracleType.NVarChar).Value = dwData["WALAENZL"].ToString(); 
          or1.Parameters.Add("WALAENB", OracleType.NVarChar).Value = dwData["WALAENB"].ToString(); 
          or1.Parameters.Add("WALAEND", OracleType.NVarChar).Value = dwData["WALAEND"].ToString(); 
          or1.Parameters.Add("WALNEUB", OracleType.NVarChar).Value = dwData["WALNEUB"].ToString(); 
          or1.Parameters.Add("WALNEUD", OracleType.NVarChar).Value = dwData["WALNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
